﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.LIB;
using YJKCopyModel.ColumnTransModel;
using YJKCopyModel.CommonTrans;
using YJKCopyModel.YJKRevitWndr;
using YJKCopyModel.TransformWall;

namespace YJKCopyModel.Forms
{
	public partial class QuickModelTransForm : System.Windows.Forms.Form
	{
		public List<WallGroupInfo> WallGroupInfoes
		{
			get
			{
				return this.m_lstWallGroupInfo;
			}
		}

		public Dictionary<DoorAndWindowConfigInfo, List<DoorAndWindowBlockRefInfo>> DoorAndWindowConfig
		{
			get
			{
				return this.m_dicSameConfigDoorWindow;
			}
		}

		public Dictionary<ColumnConfigInfo, List<ColumnLoopInfo>> ConfigColumnLoop
		{
			get
			{
				return this.m_dicSameConfigLoop;
			}
		}

		public QuickModelTransForm(Autodesk.Revit.DB.Document revitDoc, List<DoubleParaleCurve> lstWallCurve, Dictionary<DoorAndWindowConfigInfo, List<DoorAndWindowBlockRefInfo>> dicSameConfigDoorWindow, Dictionary<ColumnConfigInfo, List<ColumnLoopInfo>> dicSameConfigLoop)
		{
			this.InitializeComponent();
			this.m_revitDoc = revitDoc;
			this.m_lstWallGroupInfo = null;
			this.m_lstWallUseage = new List<string>();
			this.m_lstWallUseage.Add("建筑墙");
			this.m_lstWallUseage.Add("结构墙");
			this.GetWallInfoes(lstWallCurve);
			bool flag = dicSameConfigDoorWindow != null;
			if (flag)
			{
				this.m_dicSameConfigDoorWindow = dicSameConfigDoorWindow;
			}
			bool flag2 = dicSameConfigLoop != null;
			if (flag2)
			{
				this.m_dicSameConfigLoop = dicSameConfigLoop;
			}
		}

		private void GetWallInfoes(List<DoubleParaleCurve> lstWallCurve)
		{
			List<DoubleParaleCurve> list = new List<DoubleParaleCurve>();
			list.AddRange(lstWallCurve);
			list.Sort((DoubleParaleCurve a, DoubleParaleCurve b) => b.Width.CompareTo(a.Width));
			Dictionary<int, List<DoubleParaleCurve>> dictionary = new Dictionary<int, List<DoubleParaleCurve>>();
			foreach (DoubleParaleCurve doubleParaleCurve in list)
			{
				int key = Convert.ToInt32(AssistFunc.feetToMM(doubleParaleCurve.Width));
				bool flag = dictionary.ContainsKey(key);
				if (flag)
				{
					dictionary[key].Add(doubleParaleCurve);
				}
				else
				{
					dictionary.Add(key, new List<DoubleParaleCurve>
					{
						doubleParaleCurve
					});
				}
			}
			this.m_lstWallGroupInfo = new List<WallGroupInfo>();
			foreach (KeyValuePair<int, List<DoubleParaleCurve>> keyValuePair in dictionary)
			{
				WallGroupInfo wallGroupInfo = new WallGroupInfo();
				wallGroupInfo.IsTransform = true;
				wallGroupInfo.WallWidth = keyValuePair.Key;
				wallGroupInfo.WallType = "<程序自选>";
				wallGroupInfo.Useage = this.m_lstWallUseage[0];
				wallGroupInfo.TopOffset = 0;
				wallGroupInfo.ParaleCurves = keyValuePair.Value;
				this.m_lstWallGroupInfo.Add(wallGroupInfo);
			}
		}

		private void InitWallGrid()
		{
			List<string> docWallTypes = this.GetDocWallTypes(this.m_revitDoc);
			this.hyGridWall.Rows.Clear();
			this.hyGridWall.EditingControlShowing -= this.OnEditingControlShowing;
			this.hyGridWall.EditingControlShowing += this.OnEditingControlShowing;
			for (int i = 0; i < this.m_lstWallGroupInfo.Count; i++)
			{
				WallGroupInfo wallGroupInfo = this.m_lstWallGroupInfo[i];
				DataGridViewRow dataGridViewRow = new DataGridViewRow();
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = new DataGridViewCheckBoxCell();
				dataGridViewCheckBoxCell.Value = wallGroupInfo.IsTransform;
				dataGridViewRow.Cells.Add(dataGridViewCheckBoxCell);
				HYGridViewNumbericCell hygridViewNumbericCell = new HYGridViewNumbericCell();
				hygridViewNumbericCell.ValueRange = new MostValue(1.0, 1000.0);
				hygridViewNumbericCell.Value = wallGroupInfo.WallWidth;
				dataGridViewRow.Cells.Add(hygridViewNumbericCell);
				DataGridViewComboBoxCell dataGridViewComboBoxCell = new DataGridViewComboBoxCell();
				dataGridViewComboBoxCell.Items.Add(wallGroupInfo.WallType);
				dataGridViewComboBoxCell.Items.AddRange(docWallTypes.ToArray());
				dataGridViewComboBoxCell.Value = wallGroupInfo.WallType;
				dataGridViewRow.Cells.Add(dataGridViewComboBoxCell);
				DataGridViewComboBoxCell dataGridViewComboBoxCell2 = new DataGridViewComboBoxCell();
				dataGridViewComboBoxCell2.Items.AddRange(this.m_lstWallUseage.ToArray());
				dataGridViewComboBoxCell2.Value = wallGroupInfo.Useage;
				dataGridViewRow.Cells.Add(dataGridViewComboBoxCell2);
				HYGridViewNumbericCell hygridViewNumbericCell2 = new HYGridViewNumbericCell();
				hygridViewNumbericCell2.ValueRange = new MostValue(-10000.0, 10000.0);
				hygridViewNumbericCell2.Value = wallGroupInfo.TopOffset;
				dataGridViewRow.Cells.Add(hygridViewNumbericCell2);
				HYGridViewNumbericCell hygridViewNumbericCell3 = new HYGridViewNumbericCell();
				hygridViewNumbericCell3.ValueRange = new MostValue(0.0, 100000.0);
				hygridViewNumbericCell3.Value = wallGroupInfo.ParaleCurves.Count;
				dataGridViewRow.Cells.Add(hygridViewNumbericCell3);
				this.hyGridWall.Rows.Add(dataGridViewRow);
			}
		}

		private void InitColumnGrid()
		{
			this.hyGridColumn.EditingControlShowing -= this.OnEditingControlShowing;
			this.hyGridColumn.EditingControlShowing += this.OnEditingControlShowing;
			List<FamilySymbol> docFamilySymbols = this.GetDocFamilySymbols(this.m_revitDoc, (BuiltInCategory)(-2000100));
			List<FamilySymbol> docFamilySymbols2 = this.GetDocFamilySymbols(this.m_revitDoc, (BuiltInCategory)(-2001330));
			List<FamilySymbol> list = new List<FamilySymbol>();
			list.AddRange(docFamilySymbols);
			list.AddRange(docFamilySymbols2);
			List<string> familySymbolNames = this.GetFamilySymbolNames(list);
			familySymbolNames.Insert(0, "<程序自选>");
			List<string> list2 = new List<string>();
			list2.Add("结构柱");
			list2.Add("建筑柱");
			this.hyGridColumn.Rows.Clear();
			foreach (KeyValuePair<ColumnConfigInfo, List<ColumnLoopInfo>> keyValuePair in this.m_dicSameConfigLoop)
			{
				DataGridViewRow dataGridViewRow = new DataGridViewRow();
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = new DataGridViewCheckBoxCell();
				dataGridViewCheckBoxCell.Value = true;
				dataGridViewRow.Cells.Add(dataGridViewCheckBoxCell);
				DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
				switch (keyValuePair.Key.ThisColumnCategory)
				{
				case EColumnCategory.eStrange:
					dataGridViewTextBoxCell.Value = "异形";
					break;
				case EColumnCategory.eCircle:
					dataGridViewTextBoxCell.Value = "φ" + ((int)keyValuePair.Key.Diameter).ToString();
					break;
				case EColumnCategory.eRectangle:
					dataGridViewTextBoxCell.Value = ((int)keyValuePair.Key.Length).ToString() + "×" + ((int)keyValuePair.Key.Width).ToString();
					break;
				}
				dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
				DataGridViewComboBoxCell dataGridViewComboBoxCell = new DataGridViewComboBoxCell();
				dataGridViewComboBoxCell.Items.AddRange(familySymbolNames.ToArray());
				dataGridViewComboBoxCell.Value = familySymbolNames[0];
				dataGridViewRow.Cells.Add(dataGridViewComboBoxCell);
				DataGridViewComboBoxCell dataGridViewComboBoxCell2 = new DataGridViewComboBoxCell();
				dataGridViewComboBoxCell2.Items.AddRange(list2.ToArray());
				dataGridViewComboBoxCell2.Value = list2[0];
				dataGridViewRow.Cells.Add(dataGridViewComboBoxCell2);
				HYGridViewNumbericCell hygridViewNumbericCell = new HYGridViewNumbericCell();
				hygridViewNumbericCell.ValueRange = new MostValue(-10000.0, 10000.0);
				hygridViewNumbericCell.Value = 0;
				dataGridViewRow.Cells.Add(hygridViewNumbericCell);
				HYGridViewNumbericCell hygridViewNumbericCell2 = new HYGridViewNumbericCell();
				hygridViewNumbericCell2.ValueRange = new MostValue(0.0, 100000.0);
				hygridViewNumbericCell2.Value = keyValuePair.Value.Count;
				dataGridViewRow.Cells.Add(hygridViewNumbericCell2);
				this.hyGridColumn.Rows.Add(dataGridViewRow);
			}
		}

		private void InitWindowGrid()
		{
			this.hyGridWindow.EditingControlShowing -= this.OnEditingControlShowing;
			this.hyGridWindow.EditingControlShowing += this.OnEditingControlShowing;
			List<FamilySymbol> docFamilySymbols = this.GetDocFamilySymbols(this.m_revitDoc, (BuiltInCategory)(-2000023));
			List<FamilySymbol> docFamilySymbols2 = this.GetDocFamilySymbols(this.m_revitDoc, (BuiltInCategory)(-2000014));
			List<string> familySymbolNames = this.GetFamilySymbolNames(docFamilySymbols);
			List<string> familySymbolNames2 = this.GetFamilySymbolNames(docFamilySymbols2);
			for (int i = 0; i < familySymbolNames.Count; i++)
			{
				this.m_dicDoorFamilySymbol.Add(familySymbolNames[i], docFamilySymbols[i]);
			}
			for (int j = 0; j < familySymbolNames2.Count; j++)
			{
				this.m_dicWindowFamilySymbol.Add(familySymbolNames2[j], docFamilySymbols2[j]);
			}
			familySymbolNames.Insert(0, "<程序自选>");
			familySymbolNames2.Insert(0, "<程序自选>");
			this.hyGridWindow.Rows.Clear();
			foreach (KeyValuePair<DoorAndWindowConfigInfo, List<DoorAndWindowBlockRefInfo>> keyValuePair in this.m_dicSameConfigDoorWindow)
			{
				DoorAndWindowConfigInfo key = keyValuePair.Key;
				DataGridViewRow dataGridViewRow = new DataGridViewRow();
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = new DataGridViewCheckBoxCell();
				dataGridViewCheckBoxCell.Value = true;
				dataGridViewRow.Cells.Add(dataGridViewCheckBoxCell);
				DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
				dataGridViewTextBoxCell.Value = key.No;
				dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
				DataGridViewComboBoxCell dataGridViewComboBoxCell = new DataGridViewComboBoxCell();
				dataGridViewComboBoxCell.Items.Add("门");
				dataGridViewComboBoxCell.Items.Add("窗");
				bool flag = key.EnumCategory == EDoorAndWindowCategory.eDoor;
				if (flag)
				{
					dataGridViewComboBoxCell.Value = dataGridViewComboBoxCell.Items[0];
				}
				else
				{
					dataGridViewComboBoxCell.Value = dataGridViewComboBoxCell.Items[1];
				}
				dataGridViewRow.Cells.Add(dataGridViewComboBoxCell);
				HYGridViewNumbericCell hygridViewNumbericCell = new HYGridViewNumbericCell();
				hygridViewNumbericCell.ValueRange = new MostValue(1.0, 10000.0);
				hygridViewNumbericCell.Value = key.Width;
				dataGridViewRow.Cells.Add(hygridViewNumbericCell);
				HYGridViewNumbericCell hygridViewNumbericCell2 = new HYGridViewNumbericCell();
				hygridViewNumbericCell2.ValueRange = new MostValue(1.0, 10000.0);
				hygridViewNumbericCell2.Value = key.Height;
				bool flag2 = !key.CanAnalyseNo;
				if (flag2)
				{
					hygridViewNumbericCell2.Style.ForeColor = System.Drawing.Color.Magenta;
				}
				dataGridViewRow.Cells.Add(hygridViewNumbericCell2);
				DataGridViewComboBoxCell dataGridViewComboBoxCell2 = new DataGridViewComboBoxCell();
				bool flag3 = key.EnumCategory == EDoorAndWindowCategory.eDoor;
				if (flag3)
				{
					dataGridViewComboBoxCell2.Items.AddRange(familySymbolNames.ToArray());
					dataGridViewComboBoxCell2.Value = familySymbolNames[0];
				}
				else
				{
					dataGridViewComboBoxCell2.Items.AddRange(familySymbolNames2.ToArray());
					dataGridViewComboBoxCell2.Value = familySymbolNames2[0];
				}
				dataGridViewRow.Cells.Add(dataGridViewComboBoxCell2);
				HYGridViewNumbericCell hygridViewNumbericCell3 = new HYGridViewNumbericCell();
				hygridViewNumbericCell3.ValueRange = new MostValue(-10000.0, 10000.0);
				bool flag4 = key.EnumCategory == EDoorAndWindowCategory.eDoor;
				if (flag4)
				{
					hygridViewNumbericCell3.Value = 0;
				}
				else
				{
					hygridViewNumbericCell3.Value = 900;
				}
				dataGridViewRow.Cells.Add(hygridViewNumbericCell3);
				HYGridViewNumbericCell hygridViewNumbericCell4 = new HYGridViewNumbericCell();
				hygridViewNumbericCell4.ValueRange = new MostValue(0.0, 100000.0);
				hygridViewNumbericCell4.Value = keyValuePair.Value.Count;
				dataGridViewRow.Cells.Add(hygridViewNumbericCell4);
				this.hyGridWindow.Rows.Add(dataGridViewRow);
			}
		}

		private void UpdateWallInfoes()
		{
			for (int i = 0; i < this.hyGridWall.Rows.Count; i++)
			{
				WallGroupInfo wallGroupInfo = this.m_lstWallGroupInfo[i];
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = this.hyGridWall.GetCell(i, 0) as DataGridViewCheckBoxCell;
				wallGroupInfo.IsTransform = Convert.ToBoolean(dataGridViewCheckBoxCell.Value);
				HYGridViewNumbericCell cell = this.hyGridWall.GetCell(i, 1) as HYGridViewNumbericCell;
				wallGroupInfo.WallWidth = this.GridCellValueToInt(cell);
				DataGridViewComboBoxCell dataGridViewComboBoxCell = this.hyGridWall.GetCell(i, 2) as DataGridViewComboBoxCell;
				wallGroupInfo.WallType = Convert.ToString(dataGridViewComboBoxCell.Value);
				DataGridViewComboBoxCell dataGridViewComboBoxCell2 = this.hyGridWall.GetCell(i, 3) as DataGridViewComboBoxCell;
				wallGroupInfo.Useage = Convert.ToString(dataGridViewComboBoxCell2.Value);
				HYGridViewNumbericCell cell2 = this.hyGridWall.GetCell(i, 4) as HYGridViewNumbericCell;
				wallGroupInfo.TopOffset = this.GridCellValueToInt(cell2);
			}
		}

		private void UpdateColumnInfo()
		{
			for (int i = 0; i < this.hyGridColumn.Rows.Count; i++)
			{
				ColumnConfigInfo columnConfigInfo = this.m_dicSameConfigLoop.Keys.ElementAt(i);
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = this.hyGridColumn.GetCell(i, 0) as DataGridViewCheckBoxCell;
				columnConfigInfo.Rebuild = bool.Parse(dataGridViewCheckBoxCell.Value.ToString());
				DataGridViewComboBoxCell dataGridViewComboBoxCell = this.hyGridColumn.GetCell(i, 2) as DataGridViewComboBoxCell;
				string typeName = dataGridViewComboBoxCell.Value.ToString();
				columnConfigInfo.TypeName = typeName;
				DataGridViewComboBoxCell dataGridViewComboBoxCell2 = this.hyGridColumn.GetCell(i, 3) as DataGridViewComboBoxCell;
				bool flag = dataGridViewComboBoxCell2.Value.ToString().Contains("结构");
				if (flag)
				{
					columnConfigInfo.IsStruct = true;
				}
				else
				{
					columnConfigInfo.IsStruct = false;
				}
				HYGridViewNumbericCell hygridViewNumbericCell = this.hyGridColumn.GetCell(i, 4) as HYGridViewNumbericCell;
				columnConfigInfo.TopOffset = double.Parse(hygridViewNumbericCell.Value.ToString());
			}
		}

		private void UpdateWindowInfo()
		{
			for (int i = 0; i < this.hyGridWindow.Rows.Count; i++)
			{
				DoorAndWindowConfigInfo doorAndWindowConfigInfo = this.m_dicSameConfigDoorWindow.Keys.ElementAt(i);
				DataGridViewCheckBoxCell dataGridViewCheckBoxCell = this.hyGridWindow.GetCell(i, 0) as DataGridViewCheckBoxCell;
				doorAndWindowConfigInfo.Rebuild = bool.Parse(dataGridViewCheckBoxCell.Value.ToString());
				DataGridViewTextBoxCell dataGridViewTextBoxCell = this.hyGridWindow.GetCell(i, 1) as DataGridViewTextBoxCell;
				doorAndWindowConfigInfo.No = dataGridViewTextBoxCell.Value.ToString();
				DataGridViewComboBoxCell dataGridViewComboBoxCell = this.hyGridWindow.GetCell(i, 2) as DataGridViewComboBoxCell;
				doorAndWindowConfigInfo.EnumCategory = dataGridViewComboBoxCell.Items.IndexOf(dataGridViewComboBoxCell.Value) + EDoorAndWindowCategory.eDoor;
				HYGridViewNumbericCell hygridViewNumbericCell = this.hyGridWindow.GetCell(i, 3) as HYGridViewNumbericCell;
				doorAndWindowConfigInfo.Width = double.Parse(hygridViewNumbericCell.Value.ToString());
				HYGridViewNumbericCell hygridViewNumbericCell2 = this.hyGridWindow.GetCell(i, 4) as HYGridViewNumbericCell;
				doorAndWindowConfigInfo.Height = double.Parse(hygridViewNumbericCell2.Value.ToString());
				DataGridViewComboBoxCell dataGridViewComboBoxCell2 = this.hyGridWindow.GetCell(i, 5) as DataGridViewComboBoxCell;
				doorAndWindowConfigInfo.TypeName = dataGridViewComboBoxCell2.Value.ToString();
				HYGridViewNumbericCell hygridViewNumbericCell3 = this.hyGridWindow.GetCell(i, 6) as HYGridViewNumbericCell;
				doorAndWindowConfigInfo.BottomHeight = double.Parse(hygridViewNumbericCell3.Value.ToString());
			}
		}

		private List<string> GetDocWallTypes(Autodesk.Revit.DB.Document doc)
		{
			List<WallType> list = new List<WallType>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfClass(typeof(WallType));
			FilteredElementIterator elementIterator = filteredElementCollector.GetElementIterator();
			elementIterator.Reset();
			while (elementIterator.MoveNext())
			{
				Element element = elementIterator.Current;
				WallType wallType = element as WallType;
				bool flag = wallType != null && !list.Contains(wallType);
				if (flag)
				{
					list.Add(wallType);
				}
			}
			List<string> list2 = new List<string>();
			foreach (WallType wallType2 in list)
			{
				bool flag2 = wallType2.FamilyName.Contains("基本墙");
				if (flag2)
				{
					list2.Add(wallType2.FamilyName + ":" + wallType2.Name);
				}
			}
			foreach (WallType wallType3 in list)
			{
				bool flag3 = wallType3.FamilyName.Contains("幕墙");
				if (flag3)
				{
					list2.Add(wallType3.FamilyName + ":" + wallType3.Name);
				}
			}
			foreach (WallType wallType4 in list)
			{
				bool flag4 = wallType4.FamilyName.Contains("叠层墙");
				if (flag4)
				{
					list2.Add(wallType4.FamilyName + ":" + wallType4.Name);
				}
			}
			return list2;
		}

		private List<FamilySymbol> GetDocFamilySymbols(Autodesk.Revit.DB.Document doc, BuiltInCategory category)
		{
			List<FamilySymbol> list = new List<FamilySymbol>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			IList<FamilySymbol> list2 = filteredElementCollector.OfClass(typeof(FamilySymbol)).OfCategory(category).Cast<FamilySymbol>().ToList<FamilySymbol>();
			foreach (FamilySymbol item in list2)
			{
				list.Add(item);
			}
			return list;
		}

		private List<string> GetFamilySymbolNames(List<FamilySymbol> lstSymbol)
		{
			List<string> list = new List<string>();
			foreach (FamilySymbol familySymbol in lstSymbol)
			{
				string item = familySymbol.FamilyName + ":" + familySymbol.Name;
				bool flag = !list.Contains(item);
				if (flag)
				{
					list.Add(item);
				}
			}
			return list;
		}

		private bool CheckGridCellForInt(object cellValue)
		{
			try
			{
				int num = Convert.ToInt32(cellValue);
			}
			catch
			{
				YJKMessageBox.Show("请输入整数！");
				return false;
			}
			return true;
		}

		private bool CheckGridCellForPositive(object cellValue)
		{
			try
			{
				int num = Convert.ToInt32(cellValue);
				bool flag = num <= 0;
				if (flag)
				{
					YJKMessageBox.Show("请输入大于0的正整数！");
					return false;
				}
			}
			catch
			{
				YJKMessageBox.Show("请输入大于0的正整数！");
				return false;
			}
			return true;
		}

		private int GridCellValueToInt(DataGridViewCell cell)
		{
			int result = 0;
			bool flag = cell.Value != null;
			if (flag)
			{
				result = Convert.ToInt32(cell.Value);
			}
			else
			{
				bool flag2 = cell.FormattedValue != null;
				if (flag2)
				{
					result = Convert.ToInt32(cell.FormattedValue);
				}
			}
			return result;
		}

		private void QuickModelTransForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.InitWallGrid();
			this.InitColumnGrid();
			this.InitWindowGrid();
		}

		private void QuickModelTransForm_KeyDown(object sender, KeyEventArgs e)
		{
			bool flag = e.KeyCode == Keys.Escape;
			if (flag)
			{
				base.DialogResult = DialogResult.Cancel;
			}
		}

		private void btnPreviewType_Click(object sender, EventArgs e)
		{
		}

		private void btnStartTrans_Click(object sender, EventArgs e)
		{
			this.UpdateWallInfoes();
			this.UpdateColumnInfo();
			this.UpdateWindowInfo();
			base.DialogResult = DialogResult.OK;
		}

		private void hyGridWall_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
		{
			DataGridViewCell currentCell = this.hyGridWall.CurrentCell;
			bool flag = currentCell == null;
			if (!flag)
			{
				string headerText = currentCell.OwningColumn.HeaderText;
				bool flag2 = headerText.Contains("核心墙宽");
				if (flag2)
				{
					bool flag3 = !this.CheckGridCellForPositive(e.FormattedValue);
					if (flag3)
					{
						e.Cancel = true;
						this.hyGridWall.CancelEdit();
					}
				}
				else
				{
					bool flag4 = headerText.Contains("顶部偏移");
					if (flag4)
					{
						bool flag5 = !this.CheckGridCellForInt(e.FormattedValue);
						if (flag5)
						{
							e.Cancel = true;
							this.hyGridWall.CancelEdit();
						}
					}
				}
			}
		}

		private void hyGridColumn_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
		{
			DataGridViewCell currentCell = this.hyGridColumn.CurrentCell;
			bool flag = currentCell == null;
			if (!flag)
			{
				string headerText = currentCell.OwningColumn.HeaderText;
				bool flag2 = headerText.Contains("顶部偏移");
				if (flag2)
				{
					bool flag3 = !this.CheckGridCellForInt(e.FormattedValue);
					if (flag3)
					{
						e.Cancel = true;
						this.hyGridColumn.CancelEdit();
					}
				}
			}
		}

		private void hyGridWindow_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
		{
			DataGridViewCell currentCell = this.hyGridWindow.CurrentCell;
			bool flag = currentCell == null;
			if (!flag)
			{
				string headerText = currentCell.OwningColumn.HeaderText;
				bool flag2 = headerText.Contains("宽度");
				if (flag2)
				{
					bool flag3 = !this.CheckGridCellForPositive(e.FormattedValue);
					if (flag3)
					{
						e.Cancel = true;
						this.hyGridWindow.CancelEdit();
					}
				}
				else
				{
					bool flag4 = headerText.Contains("高度");
					if (flag4)
					{
						bool flag5 = !this.CheckGridCellForPositive(e.FormattedValue);
						if (flag5)
						{
							e.Cancel = true;
							this.hyGridWindow.CancelEdit();
						}
						currentCell.Style.ForeColor = System.Drawing.Color.Black;
					}
					else
					{
						bool flag6 = headerText.Contains("底高");
						if (flag6)
						{
							bool flag7 = !this.CheckGridCellForInt(e.FormattedValue);
							if (flag7)
							{
								e.Cancel = true;
								this.hyGridWindow.CancelEdit();
							}
						}
					}
				}
			}
		}

		private void hyGridWindow_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
			bool flag = e.RowIndex >= 0 && e.ColumnIndex == 2;
			if (flag)
			{
				DataGridViewComboBoxCell dataGridViewComboBoxCell = this.hyGridWindow.GetCell(e.RowIndex, e.ColumnIndex) as DataGridViewComboBoxCell;
				EDoorAndWindowCategory edoorAndWindowCategory = dataGridViewComboBoxCell.Items.IndexOf(dataGridViewComboBoxCell.Value) + EDoorAndWindowCategory.eDoor;
				Dictionary<string, FamilySymbol> dicDoorFamilySymbol = this.m_dicDoorFamilySymbol;
				DataGridViewComboBoxCell dataGridViewComboBoxCell2 = this.hyGridWindow.GetCell(e.RowIndex, 5) as DataGridViewComboBoxCell;
				List<string> list = new List<string>();
				bool flag2 = edoorAndWindowCategory == EDoorAndWindowCategory.eDoor;
				if (flag2)
				{
					list = this.m_dicDoorFamilySymbol.Keys.ToList<string>();
				}
				else
				{
					list = this.m_dicWindowFamilySymbol.Keys.ToList<string>();
				}
				dataGridViewComboBoxCell2.Items.Clear();
				dataGridViewComboBoxCell2.Items.Add("<程序自选>");
				dataGridViewComboBoxCell2.Items.AddRange(list.ToArray());
				dataGridViewComboBoxCell2.Value = dataGridViewComboBoxCell2.Items[0];
				HYGridViewNumbericCell hygridViewNumbericCell = this.hyGridWindow.GetCell(e.RowIndex, 6) as HYGridViewNumbericCell;
				bool flag3 = edoorAndWindowCategory == EDoorAndWindowCategory.eDoor;
				if (flag3)
				{
					hygridViewNumbericCell.Value = 0;
				}
				else
				{
					hygridViewNumbericCell.Value = 900;
				}
			}
			else
			{
				bool flag4 = e.RowIndex >= 0 && e.ColumnIndex == 5;
				if (flag4)
				{
					DataGridViewComboBoxCell dataGridViewComboBoxCell3 = this.hyGridWindow.GetCell(e.RowIndex, e.ColumnIndex) as DataGridViewComboBoxCell;
					bool flag5 = dataGridViewComboBoxCell3.Value.ToString() == "<程序自选>";
					if (flag5)
					{
						this.hyGridWindow.GetCell(e.RowIndex, 3).ReadOnly = false;
						this.hyGridWindow.GetCell(e.RowIndex, 4).ReadOnly = false;
					}
					else
					{
						this.hyGridWindow.GetCell(e.RowIndex, 3).ReadOnly = true;
						this.hyGridWindow.GetCell(e.RowIndex, 4).ReadOnly = true;
					}
				}
			}
		}

		protected void OnEditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
		{
			System.Windows.Forms.ComboBox comboBox = e.Control as System.Windows.Forms.ComboBox;
			bool flag = comboBox == null;
			if (!flag)
			{
				comboBox.DrawMode = DrawMode.OwnerDrawFixed;
				comboBox.DrawItem -= this.Combo_DrawItem;
				comboBox.DrawItem += this.Combo_DrawItem;
			}
		}

		private void Combo_DrawItem(object sender, DrawItemEventArgs e)
		{
			bool flag = sender == null || !(sender is System.Windows.Forms.ComboBox) || e.Index < 0;
			if (!flag)
			{
				System.Windows.Forms.ComboBox comboBox = sender as System.Windows.Forms.ComboBox;
				this.AdjustComboBoxDropDownListWidth(comboBox, e.Graphics, e.Font);
				e.DrawBackground();
				System.Drawing.Rectangle r = default(System.Drawing.Rectangle);
				r.Location = e.Bounds.Location;
				r.Width = comboBox.Width;
				r.Height = e.Bounds.Height;
				e.Graphics.DrawString(comboBox.Items[e.Index].ToString(), e.Font, Brushes.Black, r);
				e.DrawFocusRectangle();
			}
		}

		private void AdjustComboBoxDropDownListWidth(System.Windows.Forms.ComboBox cmb, Graphics g, Font font)
		{
			try
			{
				int num = cmb.Width;
				g = cmb.CreateGraphics();
				font = cmb.Font;
				int num2 = (cmb.Items.Count > cmb.MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0;
				foreach (object obj in cmb.Items)
				{
					bool flag = obj != null;
					if (flag)
					{
						int num3 = (int)g.MeasureString(obj.ToString().Trim(), font).Width + num2;
						bool flag2 = num < num3;
						if (flag2)
						{
							num = num3;
						}
					}
				}
				cmb.Width = num;
			}
			catch
			{
			}
			finally
			{
				bool flag3 = g != null;
				if (flag3)
				{
					g.Dispose();
				}
			}
		}

		public const string TypeOfApp = "<程序自选>";

		private Document m_revitDoc;

		private List<WallGroupInfo> m_lstWallGroupInfo;

		private List<string> m_lstWallUseage;

		private Dictionary<DoorAndWindowConfigInfo, List<DoorAndWindowBlockRefInfo>> m_dicSameConfigDoorWindow = new Dictionary<DoorAndWindowConfigInfo, List<DoorAndWindowBlockRefInfo>>();

		private Dictionary<string, FamilySymbol> m_dicDoorFamilySymbol = new Dictionary<string, FamilySymbol>();

		private Dictionary<string, FamilySymbol> m_dicWindowFamilySymbol = new Dictionary<string, FamilySymbol>();

		private EDoorAndWindowCategory m_eCategoryCellPreValue = EDoorAndWindowCategory.eNone;

		private Dictionary<ColumnConfigInfo, List<ColumnLoopInfo>> m_dicSameConfigLoop = new Dictionary<ColumnConfigInfo, List<ColumnLoopInfo>>();

		private Dictionary<string, FamilySymbol> m_dicColumnFamilySymbol = new Dictionary<string, FamilySymbol>();
	}
}
